#include <iostream>
#include <string>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        string str;
        cin >> str;
        float n = 0, v = 1;
        int k = 0;
        for (auto val : str)
        {
            if(k<=0)v=1.0;
            switch (val)
            {
            case '.':
                n += 1.0 / v;
                break;
            case 'w':
                n += 2.0 / v;
                break;
            case '>':
                if(k<=0){
                    v*=2;
                    k=5;
                }else if (k < 5)
                    k = 5;
                n += 1.0 / v;
                break;
            case 's':
                if(k>0)k-=1;
                n += 1+1.0 / v;
                break;
            case 'm':
                if(k>0)k-=2;
                n += 2+1.0 / v;
                break;
            }
            if (k > 0)
                k--;
        }
        cout << n << endl;
    }
    return 0;
}